#!/bin/sh
set -e

# GoSpeed Docker入口点脚本 - 简化版
# 直接使用GoSpeed原生支持的环境变量

echo "🚀 GoSpeed Docker容器启动中..."

# 如果提供了自定义命令，则执行它
if [ $# -gt 0 ]; then
    echo "执行自定义命令: $@"
    exec "$@"
else
    echo "启动GoSpeed服务..."
    echo "环境变量配置:"
    echo "  GOSPEED_THREAD=${GOSPEED_THREAD:-4}"
    echo "  GOSPEED_MEMORY=${GOSPEED_MEMORY:-2048} MB"
    echo "  GOSPEED_DEBUG=${GOSPEED_DEBUG:-false}"
    echo "  GOSPEED_MAX_SIZE=${GOSPEED_MAX_SIZE:-0} MB"
    echo "  GOSPEED_TIME_START=${GOSPEED_TIME_START:-9}"
    echo "  GOSPEED_TIME_STOP=${GOSPEED_TIME_STOP:-23}"
    echo "  GOSPEED_URLS=${GOSPEED_URLS:-urls.txt}"
    
    # 检查URL文件是否存在
    if [ ! -f "${GOSPEED_URLS:-urls.txt}" ]; then
        echo "⚠️ 警告: URL文件 ${GOSPEED_URLS:-urls.txt} 不存在，创建空文件..."
        touch "${GOSPEED_URLS:-urls.txt}"
    fi
    
    # 启动应用 - 无需任何参数，完全依赖环境变量
    echo "正在启动GoSpeed..."
    exec /app/GoSpeed
fi